﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DateBaseConnectionPool;
using MySql.Data.MySqlClient;
using System.Data.Common;
using System.Threading;
using System.IO;


namespace TestMySqlConnetPoll
{
    public partial class MySqlConnectPollTest : Form
    {        
        static ConnectionPool c = null;        
        MySqlConnection[] conn = new MySqlConnection[50];
        System.Windows.Forms.Timer time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertTime = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertDYP_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertUPS_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertQJGDDL_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertWDW_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertZNGDDL_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertMCGDDL_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertDCBSDY_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertXHJ_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertDMH_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertZHANLIAN_Time = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer InsertBZB_Time = new System.Windows.Forms.Timer();

        System.Timers.Timer AutoRevTimer = new System.Timers.Timer();
        System.Timers.Timer AutoRefreshRealTime = new System.Timers.Timer();

        private Thread thread_dyp;
        private Thread thread_ups;
        private Thread thread_wdw;
        private Thread thread_zngddl;
        private Thread thread_qjgddl;
        private Thread thread_mcgddl;
        private Thread thread_dcbsdy;
        private Thread thread_xhj;
        private Thread thread_dmh;
        private Thread thread_zhanlian;
        private Thread thread_bzb;
        private Thread thread_jz_fz;
        private Thread thread_dljy_lycs;
        bool TreadRun = true;


        static int c_day = 0;
        static int c_time = 0;
        static string T_labelBigCtime = "";
        static string T_labelBigStime = "";
        
        static Dictionary<string, List<byte>> li = new Dictionary<string, List<byte>>();
        static Dictionary<string, List<long>> li_15 = new Dictionary<string, List<long>>();

        int DesignColumnNum = 0;            //表的列数
        int DesignMaxSize_Column = 0;       //每列的填充字节数    
        byte TableType = 0;

        static int TableCountSum = 0;

        

        public enum Mysql_OperateType
        {
            Count,
            Insert,
            Select,
            Delete
        };

        public struct MySQL_Operation
        {
            public Mysql_OperateType OperateType;      //操作类型
            public string TableName;                   //表名
            public int StartUtime;                     //开始时间
            public int EndUtime;                       //结束时间
            public string SecName;                     //设备名称
            public int LimitNow;                       //取的限制行数
            public int p_day;                          //分区的天数
            public string ColNameSet;                  //取的列名集合.            
        };

        void c_RealTimeValue_NewAlarmEvent(Object sender, EventArgs e)
        { }

        void c_RealTimeValue_MessgeInfo(object sender, MessageInfoEventArgs e)
        {}

        public MySqlConnectPollTest()
        {




            InitializeComponent();
            time.Interval = 200;
            time.Tick += new EventHandler(time_Tick);
            time.Start();

            //InsertTime.Interval = 1000;     //每秒启动一次
            //InsertTime.Tick +=new EventHandler(InsertTime_Tick);
            //InsertTime.Start();

            int tmptimeInterval = 5000;

            InsertDCBSDY_Time.Interval = tmptimeInterval;
            InsertDCBSDY_Time.Tick += new EventHandler(InsertDCBSDY_Time_Tick);
            //InsertDCBSDY_Time.Start();

            InsertDMH_Time.Interval = tmptimeInterval;
            InsertDMH_Time.Tick += new EventHandler(InsertDMH_Time_Tick);
            //InsertDMH_Time.Start();

            InsertDYP_Time.Interval = tmptimeInterval;
            InsertDYP_Time.Tick += new EventHandler(InsertDYP_Time_Tick);
            //InsertDYP_Time.Start();

            InsertMCGDDL_Time.Interval = tmptimeInterval;
            InsertMCGDDL_Time.Tick += new EventHandler(InsertMCGDDL_Time_Tick);
            //InsertMCGDDL_Time.Start();

            InsertQJGDDL_Time.Interval = tmptimeInterval;
            InsertQJGDDL_Time.Tick += new EventHandler(InsertQJGDDL_Time_Tick);
            //InsertQJGDDL_Time.Start();

            InsertUPS_Time.Interval = tmptimeInterval;
            InsertUPS_Time.Tick += new EventHandler(InsertUPS_Time_Tick);
            //InsertUPS_Time.Start();

            InsertWDW_Time.Interval = tmptimeInterval;
            InsertWDW_Time.Tick += new EventHandler(InsertWDW_Time_Tick);
            //InsertWDW_Time.Start();

            InsertXHJ_Time.Interval = tmptimeInterval;
            InsertXHJ_Time.Tick += new EventHandler(InsertXHJ_Time_Tick);
            //InsertXHJ_Time.Start();

            InsertZHANLIAN_Time.Interval = tmptimeInterval;
            InsertZHANLIAN_Time.Tick += new EventHandler(InsertZHANLIAN_Time_Tick);
            //InsertZHANLIAN_Time.Start();

            InsertZNGDDL_Time.Interval = tmptimeInterval;
            InsertZNGDDL_Time.Tick += new EventHandler(InsertZNGDDL_Time_Tick);
            //InsertZNGDDL_Time.Start();

            InsertBZB_Time.Interval = tmptimeInterval;
            InsertBZB_Time.Tick += new EventHandler(InsertBZB_Time_Tick);
            //InsertBZB_Time.Start();

            textDB_NAME.Text = "CSM2010";
            Min_Int.Text = "5";
            Max_Int.Text = "20";
            ReaptNum.Text = "10";
            CreateNum.Text = "5";
            keepNumNum.Text = "5";
            TimeOut.Text = "30";
            ConnectSum.Text = "";
            OnUseSum.Text = "";
            NullSum.Text = "";

            Apply_Comm.Enabled = false;
            button_Dispose.Enabled = false;
            stopServers.Enabled = false;
            c_time = (int)DateTimeToTime_t(DateTime.Now);
            c_day = DateTime.Now.Day;
            DesignColumnNum = 31;
            DesignMaxSize_Column = 1000;

            thread_bzb = new Thread(new ThreadStart(ThreadbzbProcess));
            thread_wdw = new Thread(new ThreadStart(ThreadwdwProcess));
            thread_dyp = new Thread(new ThreadStart(ThreaddypProcess));
            thread_ups = new Thread(new ThreadStart(ThreadupsProcess));
            thread_zngddl = new Thread(new ThreadStart(ThreadzngddlProcess));
            thread_mcgddl = new Thread(new ThreadStart(ThreadmcgddlProcess));
            thread_qjgddl = new Thread(new ThreadStart(ThreadqjgddlProcess));
            thread_dcbsdy = new Thread(new ThreadStart(ThreaddcbsdyProcess));
            thread_dmh = new Thread(new ThreadStart(ThreaddmhProcess));
            thread_xhj = new Thread(new ThreadStart(ThreadxhjProcess));
            thread_zhanlian = new Thread(new ThreadStart(ThreadzhanlianProcess));
            //ThreadPool.QueueUserWorkItem(new WaitCallback(MySql_Thread));
            //StartServer_Click();
            MySql.InitMySql("csm2014", "192.168.10.222");
            INIFile INIF = new INIFile();
            string s = INIF.GetINI_FilePath();
            INIF.Read_DC_INI(s + "\\dc.ini");
            INIF.Read_GD_INI(s + "\\gd.ini");
            INIF.Read_JC_INI(s + "\\jc.ini");
            INIF.Read_ZH_INI(s + "\\zh.ini");
            INIF.Read_XHJ_INI(s + "\\xhj.ini");
            INIF.Read_YP_INI(s + "\\yp.ini");
            INIF.Read_LK1_INI(s + "\\lk1.ini");
            INIF.Read_Digit_INI(s + "\\digit.ini");            
            INIF.Read_FLBL_INI(s + "\\flbl.ini");
            INIF.ReadOther_INI(s + "\\other.ini");
            INIF.ReadDCQK_INI(s + "\\dcqk.ini");
            INIF.ReadHK_INI(s + "hk.ini");
            INIF.ReadSysConfig_INI();
            INIF.Read_MsgGather_INI(s + "\\msggather.ini");
            c_Device.InitButtenUseConfig();
            c_Device.InitCy_DevList();
            c_Device.InitDcdlqxDevList();
            c_Device.InitGybdcDYbx_DevList();
            c_Device.InitSysLogConfig();
            c_Device.InitTongJiConfig();
            c_Device.InitUserScanAnnalConfig();
            c_Device.InitWdwErrorQX_DevList();
            c_LK.Init_c_LK();
            C_MyPipe.StartPipeClient();

            c_RealTimeValue.InitRealTimeData();
            c_NetCom.InitNetCom();
            c_NetData.InitNetData();
            c_ReceiveData.StartRevPipeData();

            c_ReceiveData.NewAlarmEvent += new EventHandler(c_RealTimeValue_NewAlarmEvent);
            c_RealTimeValue.MessageInfo += new EventHandler<MessageInfoEventArgs>(c_RealTimeValue_MessgeInfo);

            short vv = 8193;
            c_RealTimeValue.ConvertAnalogValue("载频", vv);

            byte[]siiii = new byte[7];
            siiii[0] = 0x49 ;
            siiii[1] = 0xC2 ;
            siiii[2] = 0xB7 ;
            siiii[3] = 0xB4 ;
            siiii[4] = 0xED ;
            siiii[5] = 0xD0 ;
            siiii[6] = 0xF2;
            CSM_DevType ttttttt = CSM_DevType.ups;
            string tttttts = c_Device.GetDevTypeName(ttttttt);
            string siiiiii = System.Text.Encoding.Default.GetString(siiii);

            string testiii = "I路错序";

            byte[] testuu = System.Text.Encoding.UTF8.GetBytes(testiii);

            string ifif = System.Text.Encoding.UTF8.GetString(testuu);

            int klkk = MySql.DateTimeToTime_t(new DateTime(2014, 5, 10, 0, 0, 0));

            int klkkff = MySql.DateTimeToTime_t(new DateTime(2014, 5, 14, 0, 0, 0));

            int tfff = 41143;
          ObjValue tkkkkkk =  c_RealTimeValue.ConvertAnalogValue("外电网", (short)tfff);
            //c_RealTimeValue.RefreshRealTimeValue();
            //float k = 0;
            //int kk = 12345;
            //Console.WriteLine(DateTime.Now.ToString());
            Dictionary<objCodeDev, string> testdic = new Dictionary<objCodeDev, string>();
            objCodeDev testc = new objCodeDev();
            testc.codetype = 1;
            testc.dev_no = 12;
            testdic.Add(testc, "test");
            if (testdic.ContainsKey(testc))
            {
                int testdf = 10;
            }
            //k = (float)kk/1000;
            //int m = (int)k;
            //Console.WriteLine(k.ToString());
            //Console.WriteLine(m.ToString());
            DateTime dttt = new DateTime(2014, 3, 4, 5, 6, 0);
            long dtkk = MySql.DateTimeToTime_t(dttt);
            DateTime kttt = MySql.Time_tToDateTime((int)dtkk);
            List<int> kkkt = new List<int>();
            for (int i = 0; i < 1000; i++)
            {
                kkkt.Add(i);
            }
            kkkt.RemoveRange(0, 10);

            List<HigFreAnalogValue> xx = new List<HigFreAnalogValue>();
            HigFreAnalogValue x = new HigFreAnalogValue();
            x.utime = 1000;
            xx.Add(x);
            x = new HigFreAnalogValue();
            x.utime = 2000;
            xx.Add(x);
            if (xx.Exists(o => o.utime == 1000))
            {
                Console.WriteLine("---");
            }
            x = new HigFreAnalogValue();
            x.utime = 1000;
            if (xx.Contains(x))
            {
                Console.WriteLine("0000");
            }
            objRevKGL sss1 = new objRevKGL();
            sss1.AllFlag = true;
            sss1.kglNum = 1000;
            sss1.time = 34543;
            for (int i = 0; i < 200; i++)
            {
                sss1.Value.Add((byte)i);
            }
            objRevKGL s89 = new objRevKGL();

            s89 = c_NetData.Clone(sss1) as objRevKGL;

            sss1.AllFlag = false;
            sss1.kglNum = 500;
            sss1.time = 03658;
            sss1.Value.Clear();

            byte[] lll = new byte[4];
            lll[2] = 0x98;
            List<byte> llli = new List<byte>();
            llli.AddRange(lll);
            lll = new byte[2];
            llli.AddRange(lll);

            List<int> t1 = new List<int>();
            t1.Add(1);
            List<int> t2 = new List<int>();
            t2.Add(2);

            t1.AddRange(t2);

            t2.Clear();
            List<objTimeValue> t6 = new List<objTimeValue>();
            objTimeValue sss = new objTimeValue();
            for (int i = 0; i < 20; i++)
            {
                sss.u_time = i * 10;
                t6.Add(sss);
            }
            int etime = 500;

            List<objTimeValue> t7 = new List<objTimeValue>();

            objTimeValue firstObj = new objTimeValue();
            objTimeValue NextObj = new objTimeValue();
            for (int i = 0; i < t6.Count - 1; i++)      //补中间的差点
            {
                firstObj = t6[i];
                NextObj = t6[i + 1];
                int needdot = NextObj.u_time - firstObj.u_time - 1;
                t7.Add(firstObj);
                objTimeValue bdot = new objTimeValue();
                bdot = firstObj;
                for (int j = 0; j < needdot; j++)
                {
                    bdot.u_time += 1;
                    t7.Add(bdot);
                }
            }
            t7.Add(t6[t6.Count - 1]);   //把t6的最后一个点加进去
            int needdot1 = etime - t6[t6.Count - 1].u_time;

            objTimeValue bdot1 = new objTimeValue();
            bdot1 = t6[t6.Count - 1];
            for (int i = 0; i < needdot1; i++)  //补最后一个有效点到结束时间的点。
            {
                bdot1.u_time++;
                t7.Add(bdot1);
            }

            List<objTimeValue> ki = new List<objTimeValue>();
            objTimeValue km = new objTimeValue();
            km.u_time = 1;
            km.Dvalue = 100;
            km.Tvalue.Value = 100;
            ki.Add(km);

            km.u_time = 10;
            km.Dvalue = 120;
            km.Tvalue.Value = 120;
            ki.Add(km);

            km.u_time = 15;
            km.Dvalue = 160;
            km.Tvalue.Value = 120;
            ki.Add(km);

            km.u_time = 22;
            km.Dvalue = 220;
            km.Tvalue.Value = 120;
            ki.Add(km);

            List<objTimeValue> kii = new List<objTimeValue>();

            objTimeValue fobj = new objTimeValue();     //最开始的一个点                        
            for (int r = 0; r < ki.Count; r++)
            {
                if (r == 0)
                {
                    fobj = ki[r];   //第一个点
                    kii.Add(fobj);
                }
                else
                {
                    objTimeValue nobj = new objTimeValue();
                    nobj = ki[r];  //第2个点
                    int n = nobj.u_time - fobj.u_time;
                    if (n >= 10)    //超过10秒无数据，认为是断开,填-1值
                    {
                        fobj.Dvalue = -1;
                        fobj.Tvalue.DecimalNum = 0;
                        fobj.Tvalue.Value = -1;
                        fobj.Tvalue.ValueType = "";
                    }
                    for (int y = 0; y < n - 1; y++) //要补点的数目
                    {
                        fobj.u_time++;
                        kii.Add(fobj);
                    }
                    kii.Add(nobj);
                    fobj = nobj;
                }
            }
            ki = kii;

            DailyReportTable tdb = new DailyReportTable();
            tdb.ReadDailyReportValueList(new objDate(2014, 5, 21), "外电网");

            Dictionary<string, List<int>> lii = new Dictionary<string, List<int>>();
            string key = "sss";
            for (int i = 5; i < 20; i++)
            {
                if (lii.ContainsKey(key))
                {
                    lii[key].Add(i);
                }
                else
                {
                    List<int> kki = new List<int>();
                    kki.Add(i);
                    lii.Add(key, kki);
                    kki = new List<int>();
                }
            }


            DateTime now = DateTime.Now;
            DateTime tt = new DateTime(2013, 3, 20);
            TimeSpan ttt = now - tt;
            DateTime ab = new DateTime();
            ab = now;
            now = tt;
            byte[] ss = new byte[3];
            ss[0] = 0x32;
            ss[1] = 0x43;
            ss[2] = 0x34;
            string strdcode = System.Text.UTF8Encoding.UTF8.GetString(ss);

            byte[] kk = System.Text.UTF8Encoding.UTF8.GetBytes(strdcode);

            byte[] t = new byte[600 * 1024];
            t[0] = 5;
            t[1] = 6;
            t[2] = 89;
            t[3] = 43;
            //c_ReceiveData.WriteMeroryMappiong(0, 4, t);
            for (int ii = 0; ii < 580000; ii++)
            {
                t[ii] = (byte)(ii + 3 * ii);
            }
            //c_ReceiveData.WriteMeroryMappiong(23030, 580000, t);
            //c_ReceiveData.ReadMemoryMapping();
            byte[] destBuf = new byte[580000];
            byte[] udestBuf = new byte[580000];
            int ulen = 580000;
            int len = 580000 / 4;
            c_NetCom.zCompress(t, 580000, destBuf, ref len, 0);
            c_NetCom.zUNcompress(destBuf, len, udestBuf, ref ulen, 0);
            List<byte> li = new List<byte>();
            //li.AddRange(destBuf);
            for (int i = 0; i < 1000; i++)
            {
                li.Add(destBuf[i]);
            }
            li[0] = 88;
            for (int i = 0; i < 1000; i++)
            {
                destBuf[i] = 0;
            }
            Console.WriteLine("ce");
            //Array.Copy(destBuf, 0, li.ToArray(), 0, 100);
            //   destBuf = new byte[10000];
            //c_RealTimeValue.MessageInfo += new EventHandler<MessageInfoEventArgs>();
            //objFLBL_Struct objFlbl = new objFLBL_Struct();
            //objFlbl.SectionName = "2-45G";
            //objFlbl.SectionType = 3;
            //objFlbl.FlblType = 1;
            //objFlbl.FlblReason = "轨面生锈";
            //objFlbl.PersonID = 1369;
            //INIF.Modify_FlblSetValue(objFlbl);

            //objFlbl.SectionName = "IIG";
            //objFlbl.SectionType = 1;
            //objFlbl.FlblType = 1;
            //objFlbl.FlblReason = "uiioioi";
            //objFlbl.PersonID = 1005;
            //INIF.Modify_FlblSetValue(objFlbl);

            //objFlbl.SectionName = "IIIG";
            //objFlbl.SectionType = 1;
            //objFlbl.FlblType = 1;
            //objFlbl.FlblReason = "粉尘";
            //objFlbl.PersonID = 1005;
            //INIF.Modify_FlblSetValue(objFlbl);
            
            AutoRevTimer.Elapsed += new System.Timers.ElapsedEventHandler(AutoRevTimer_Elapsed);
            AutoRevTimer.AutoReset = true;
            AutoRevTimer.Enabled = true;
            AutoRevTimer.Interval = 800;
            AutoRefreshRealTime.Elapsed += new System.Timers.ElapsedEventHandler(AutoRefreshRealTime_Elapsed);
            AutoRefreshRealTime.AutoReset = true;
            AutoRefreshRealTime.Enabled = true;
            AutoRefreshRealTime.Interval = 800;

            string ssss = "电源屏I路A相";
            char[] cc = ssss.ToCharArray();

            string s22 = new string(cc);

            AlarmTable tb = new AlarmTable();

            tb.ReadTimeList(1);

            ObjAlaram ala = new ObjAlaram();
            ala.u_time = MySql.DateTimeToTime_t(DateTime.Now);
            ala.AlarmLevel = 1;
            ala.AlarmType = 1;
            ala.AlarmText = "测试SJ锁闭封连报警";

            ala.dev_type = (byte)AnalogCodeType.电源屏;
            ala.dev_no = 1;
            ala.devName = "电源屏I路A相";

            ala.e_time = 0;
            ala.ex_AlarmType = 0;
            ala.tcFlag = 0;
            ala.d_time = 0;
            ala.ConfirmTime = 0;
            //ala.ConfirmText.Initialize();

            ala.ConfirmName = "张三";

            ala.statue = 0;
            List<ObjAlaram> alalist = new List<ObjAlaram>();
            alalist.Add(ala);


            ObjAlaram ala1 = new ObjAlaram();
            ala1.u_time = MySql.DateTimeToTime_t(new DateTime(2014, 5, 4, 12, 34, 43));
            ala1.AlarmLevel = 1;
            ala1.AlarmType = 1;
            ala1.AlarmText = "测试SJ锁闭封连报警";

            ala1.dev_type = (byte)AnalogCodeType.电源屏;
            ala1.dev_no = 1;
            ala1.devName = "电源屏I路A相";

            ala1.e_time = 0;
            ala1.ex_AlarmType = 0;
            ala1.tcFlag = 0;
            ala1.d_time = 0;
            ala1.ConfirmTime = 0;
            //ala.ConfirmText.Initialize();

            ala1.ConfirmName = "王五";

            ala1.statue = 0;
            alalist.Add(ala1);
            //tb.InsertData_AlarmTable(alalist);

            objDate d = new objDate();
            d.year = 2014;
            d.month = 5;
            d.day = 7;
            string altype = "";
            string atype = "";
            string adev = "";
            DateTime stim = DateTime.Now;
            DateTime etim = DateTime.MinValue;
            ////tb.Read_ValueList( stim, etim, altype, 2, "", adev);

            //while (!tb.Ready_AlarmValueList)
            //{
            //    if (tb.ErrorFlag != 0) break;
            //    Thread.Sleep(20);
            //}

            rtAlarmTable rtable = new rtAlarmTable();
            foreach (byte k in tb.ValueList.Keys)
            {
                rtable.Insert(tb.ValueList[k]);
            }

            rtable.Read();
            while (!rtable.Ready_Read)
            {
                if (rtable.ErrorFlag != 0) break;
                Thread.Sleep(20);
            }
            //if (rtable.ValueList.Count > 0)
            //{
            //    foreach (byte k in tb.ValueList.Keys)
            //    {
            //        rtable.Delete(tb.ValueList[k]);
            //    }
            //}

            ButtenUseTable bttb = new ButtenUseTable();
            objButton obu = new objButton();
            obu.s_time = MySql.DateTimeToTime_t(DateTime.Now);
            obu.e_time = obu.s_time + 20;
            bttb.InsertTableData(d, 12, obu);
            bttb.ReadTimeList();
            bttb.ReadValueList(d);

            DailyReportTable drtb = new DailyReportTable();
            d.day = 31;
            d.month = 4;
            d.year = 2014;
            drtb.ReadMonthCurveValueList(d, "电源屏", "电源屏I路A相");

            while (!drtb.Ready_MonthCurveValueList)
            {
                if (drtb.MonthErrorFlag != 0) break;
                Thread.Sleep(20);
            }

            drtb.ReadYearCurveValueList(d, "电源屏", "电源屏I路A相");

            while (!drtb.Ready_YearCurveValueList)
            {
                if (drtb.YearErrorFlag != 0) break;
                Thread.Sleep(20);
            }

            DcdlqxTable dctb = new DcdlqxTable();
            dctb.Read_DcdlqxTimeList("1-J1#");

            while (!dctb.Ready_DcdlqxTime)
            {
                if (dctb.dlqxErrorFlag != 0) break;
                Thread.Sleep(20);
            }
            int dcount = dctb.DcdlqxTimeList.Count;
            if (dcount >= 5)
            {
                dctb.Read_DcdlqxValueList(dctb.DcdlqxTimeList[0], "1-J1#");
                while (!dctb.Ready_DcdlqxValue)
                {
                    if (dctb.dlqxErrorFlag != 0) break;
                    Thread.Sleep(20);
                }
                if (dctb.DcdlqxValueList.Keys.Contains(dctb.DcdlqxTimeList[0]))
                    dctb.InsertDcCkMcQxTable(1, dctb.DcdlqxValueList[dctb.DcdlqxTimeList[0]]);
            }
            dctb.Read_DcCkValueList("1-J1#");

            while (!dctb.Ready_DcdzCKValue)
            {
                if (dctb.ckqxErrorFlag != 0) break;
                Thread.Sleep(20);
            }

            if (dctb.DcdzCKqxValueList.Count == 1)
            { }

            dctb.Read_DcMCValueList("1-J1#");

            while (!dctb.Ready_DcdzMcValue)
            {
                Thread.Sleep(20);
            }

            if (dctb.DcdzMcqxValueList.Count == 1)
            { }

            GybdcQxTable gybdc = new GybdcQxTable();
            int gyu_time = MySql.DateTimeToTime_t(DateTime.Now);
            int gyst1 = 0;
            int gyst2 = 3000;
            int gyst3 = 6000;
            int gycodetype = 0x13;
            Int16 gydev_no = 1;
            Int16 gydotNum1 = 2000;
            byte[] qx1 = new byte[4000];
            Int16 gydotNum2 = 2000;
            byte[] qx2 = new byte[4000];
            Int16 dotNum3 = 2000;
            byte[] qx3 = new byte[4000];
            int gm = 0;
            for (int gy = 0; gy < 2000; gy++)
            {
                qx1[gm] = 20;
                qx2[gm] = 30;
                qx3[gm] = 40;
                qx1[gm+1] = 0;
                qx2[gm+1] = 0;
                qx3[gm+1] = 0;
                gm+=2;
            }
            gybdc.InsertGYBDCqxTable(gyu_time, gycodetype, gydev_no, gydotNum1, gyst1, qx1, gydotNum2, gyst2, qx2, dotNum3, gyst3, qx3);

            gybdc.ReadTimeList("");
            while (!gybdc.Ready_TimeList)
            {
                Thread.Sleep(20);
            }
            if (gybdc.TimeList.Count > 0)
            {
                gybdc.ReadValueList("", gybdc.TimeList[1]);
                while (!gybdc.Ready_ValueList)
                {
                    Thread.Sleep(20);
                }
            }

            

            JyLlCyTable jytb = new JyLlCyTable();
            Int32 jyu_time = MySql.DateTimeToTime_t(DateTime.Now);
            CSM_DevType devtype = CSM_DevType.绝缘;
            AnalogCodeType codetype = AnalogCodeType.电缆绝缘;
            Int16 Dev_no = 2;
            Int16 value = 480;
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 3, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 4, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 5, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 6, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 7, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 8, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 9, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 10, value);
            devtype = CSM_DevType.残压;
            codetype = AnalogCodeType.分路残压;
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 3, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 4, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 5, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 6, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 7, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 8, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 9, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 10, value);
            devtype = CSM_DevType.漏流;
            codetype = AnalogCodeType.电源漏流;
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 3, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 4, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 5, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 6, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 7, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 8, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 9, value);
            jytb.InsertJy_Ly_Cy_Data(jyu_time, devtype, codetype, 10, value);


            devtype = CSM_DevType.绝缘;
            codetype = AnalogCodeType.电缆绝缘;
            Dev_no = 2;
            value = 365;
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 3, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 4, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 5, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 6, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 7, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 8, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 9, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 10, value);
            devtype = CSM_DevType.残压;
            codetype = AnalogCodeType.分路残压;
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 3, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 4, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 5, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 6, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 7, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 8, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 9, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 10, value);
            devtype = CSM_DevType.漏流;
            codetype = AnalogCodeType.电源漏流;
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, Dev_no, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 3, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 4, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 5, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 6, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 7, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 8, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 9, value);
            jytb.InsertToNewstJyLlCyTable(jyu_time, devtype, codetype, 10, value);

            jytb.ReadDailyReportValue("电缆绝缘", new objDate(2014, 5, 7));
            jytb.ReadMonthCurveValue("电缆绝缘", "X-HH", "绝缘测试值", 2014, 5);
            jytb.ReadYearCurveValue("电缆绝缘", "X-HH", "绝缘测试值", 2014);

            jytb.ReadJyLlCyNewstValue("电缆绝缘");

            while (!jytb.Ready_JyNewstValue)
            {
                Thread.Sleep(20);
            }
            if (jytb.Jy_NewstValueList.ContainsKey("1"))
            {
            }



            KGL_Table kgltb = new KGL_Table();
            //          kgltb.Read_KGL_ValueList(1);

            //           kgltb.Read_KGL_ValueList(1396281600, 1396396800);

            kgltb.Read_KGL_ValueList(1396281600, 1396357459);

            UserScanTable usstb = new UserScanTable();
            string ScanType = "设备浏览记录";
            string ScanNo = "电源屏日报表";
            objTableScanAnnal usobj = new objTableScanAnnal(MySql.DateTimeToTime_t(DateTime.Now), MySql.DateTimeToTime_t(now) + 200);
            usstb.InsertTableScanData(ScanType, ScanNo, usobj);
            ScanNo = "电源屏日曲线";
            usstb.InsertTableScanData(ScanType, ScanNo, usobj);
            usstb.Read_ValueList("设备浏览记录", DateTime.Now);

            ProgarmRunTimeTable protb = new ProgarmRunTimeTable();
            protb.Read_TimeList();

            SysLogTable systb = new SysLogTable();
            systb.InsertTable("用户操作日志", "测试插入广泛地撒旦法范德萨发生放大放大是放大法");

            systb.InsertTable("用户操作日志", "话很听话太皇太后太皇太后");

            systb.ReadValueList(new objDate(2014, 5, 12), "用户操作日志");

            TianChuangXiuTable tctable = new TianChuangXiuTable();
            objTianChuang objtc = new objTianChuang();
            objtc.type = 1;
            objtc.s_time = MySql.DateTimeToTime_t(DateTime.Now);
            objtc.WorkText = "上行测试天窗";
            objtc.UserName = "王五";
            objtc.e_time = objtc.s_time + 30000;

            tctable.InsertTable(new objDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day), objtc);

            //tctable.delteTianChuangValue(new objDate(2014, 5, 7), objtc);

            tctable.ReadValueList(new objDate(2014, 5, 7), new objDate(2014, 5, 7));

            string TestString = "留级sdikjljlj";
            byte[] testB = System.Text.Encoding.Default.GetBytes(TestString);
            int tlen = testB.Length;
            List<byte> TestLi = new List<byte>();
            TestLi.AddRange(testB);
            TestString = "三生三世枕上书";
            testB = System.Text.Encoding.Default.GetBytes(TestString);
            int blen = testB.Length;
            TestLi.AddRange(testB);
            string TTS = System.Text.Encoding.Default.GetString(TestLi.ToArray(), 0, tlen);
            string TTL = System.Text.Encoding.Default.GetString(TestLi.ToArray(), tlen, blen);

            float testf = 340.3445f;
            string tests = testf.ToString();
            float tttr = float.Parse(tests);

            TongJiTable tjtb = new TongJiTable();
            byte DevType = 0x61;
            Int16 DevNo = 1;
            objTongJiReport obj = new objTongJiReport(2014, 5, 30, 45);
            tjtb.InsertDateTable(DevType, DevNo, obj);
            tjtb.InsertDateTable(DevType, 2, obj);
            tjtb.InsertDateTable(DevType, 3, obj);
            tjtb.InsertDateTable(DevType, 4, obj);
            tjtb.InsertDateTable(DevType, 5, obj);
            tjtb.InsertDateTable(DevType, 6, obj);
            tjtb.ReadTimeList("区段占用次数统计");
            while (!tjtb.Ready_TimeList)
            {
                Thread.Sleep(20);
            }
            if (tjtb.TimeList.Count == 0)
            { }
            tjtb.ReadValueList("区段占用次数统计", 2014, 5);
            while (!tjtb.Ready_ValueList)
            {
                Thread.Sleep(20);
            }
            if (tjtb.ValueList.Count == 0)
            { }

            TimeAdjustTable timetb = new TimeAdjustTable();
            timetb.InsertData(MySql.DateTimeToTime_t(DateTime.Now), MySql.DateTimeToTime_t(DateTime.Now) + 10000);

            timetb.ReadValueList();
            while (!timetb.ReadyValueList)
            {
                Thread.Sleep(20);
            }

            WdwSjddTable wdwtb = new WdwSjddTable();
            AnalogCodeType wdwcodetype = AnalogCodeType.外电网;
            Int16 wdwdev_no = 1;
            int wdwu_time = MySql.DateTimeToTime_t(DateTime.Now);
            Int16 wdwdotNum = 100;
            byte[] dlA = new  byte[200];
            byte[]dlB = new byte[200];
            byte[]dlC = new byte[200];
            byte[]dyA = new byte[200];
            byte[]dyB = new byte[200];
            byte[] dyC = new byte[200];
            int wm = 0;
            for (int i = 0; i < 100; i++)
            {
                dlA[wm] = 30;
                dlB[wm] = 30;
                dlC[wm] = 30;
                dyA[wm] = 30;
                dyB[wm] = 30;
                dyC[wm] = 30;
                wm++;
                dlA[wm] = 0;
                dlB[wm] = 0;
                dlC[wm] = 0;
                dyA[wm] = 0;
                dyB[wm] = 0;
                dyC[wm] = 0;
                wm++;
            }
            wdwtb.InsertWdwsjddTable(wdwcodetype, wdwdev_no, wdwu_time, wdwdotNum, wdwdotNum, wdwdotNum, dlA, dlB, dlC, dyA, dyB, dyC);

            wdwtb.ReadTimeList("II路");
            while (!wdwtb.ReadyTimeList)
            {
                Thread.Sleep(20);
            }
            if (wdwtb.TimeList.Count > 0)
            {
                wdwtb.ReadValueList("II路", wdwtb.TimeList[0]);
            }
            while (!wdwtb.ReadyValueList)
            {
                Thread.Sleep(20);
            }

            UserTable ustb = new UserTable();
            ustb.InsertTable(new objUser(1, "溜溜", "12345", 1));
            ustb.ReadUserList();
            while (!ustb.ReadyUserList)
            {
                Thread.Sleep(20);
            }
            ustb.InsertTable(new objUser(2, "蓝精灵", "12345", 1));
            ustb.DelUser(new objUser(1, "溜溜", "12345", 1));

            LK_Table lktb = new LK_Table();
            lktb.InitLKTable();
            byte lkp_day = 9;
                 byte lktype = 0x14;
                     Int32 lku_time = MySql.DateTimeToTime_t(DateTime.Now);
            int abflag = 0x55;
            int zbflag = 0x55;
            Int16 lklen = 512;
            byte[] lkAValue = new byte[512];
            byte[] lkBValue = new byte[512];
            for (int i = 0; i < 512; i++)
            {
                lkAValue[i] = 32;
                lkBValue[i] = 56;
            }
            //lktb.InsertLK_Table(lkp_day, lktype, lku_time, abflag, zbflag, lklen, lkAValue, lkBValue);
            DateTime lkdt = new DateTime(2014,04,18);
            lktb.ReadValueList(lkdt, "列控中心主机硬件平台");
            while (!lktb.ReadyDataTable)
            {
                Thread.Sleep(20);
            }
            lktb.ReadTimeList(1);

            while (!lktb.ReadyTime)
            {
                Thread.Sleep(20);
            }
            //MySql.ReadReplayData(MySql.DateTimeToTime_t(new DateTime(2014, 5, 23)), MySql.DateTimeToTime_t(new DateTime(2014, 5, 24, 23, 59, 59)));
            DateTime mstime = new DateTime(2014,5,23);
            DateTime metime = new DateTime(2014, 5, 24, 23, 59, 59);
            MySql.ReadReplayData(mstime, (int)metime.Subtract(mstime).TotalMinutes);
        }


        private void AutoRevTimer_Elapsed(object obj, System.Timers.ElapsedEventArgs e)
        {
            //c_ReceiveData.
        }
        private void AutoRefreshRealTime_Elapsed(object obj, System.Timers.ElapsedEventArgs e)
        {
            //c_RealTimeValue.RefreshRealTimeData();
        }

        int InsertRow_Sum = 1;
        int InsertDev_Sum = 150;

        private void ThreadzhanlianProcess()
        {
            while (TreadRun)
            {
                InsertData("zhanlian", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("zhanlian_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("zhanlian_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(8000);
            }
        }

        private void ThreadxhjProcess()
        {
            while (TreadRun)
            {
                InsertData("xhj", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("xhj_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("xhj_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(7000);
            }
        }

        private void ThreaddmhProcess()
        {
            while (TreadRun)
            {
                InsertData("dmh", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("dmh_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("dmh_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(9000);
            }
        }

        private void ThreaddcbsdyProcess()
        {
            while (TreadRun)
            {
                InsertData("dcbsdy", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("dcbsdy_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("dcbsdy_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(10000);
            }
        }

        private void ThreadmcgddlProcess()
        {
            while (TreadRun)
            {
                InsertData("mcgddl", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("mcgddl_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("mcgddl_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(11000);
            }
        }

        private void ThreadzngddlProcess()
        {
            while (TreadRun)
            {
                InsertData("zngddl", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("zngddl_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("zngddl_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(9500);
            }
        }

        private void ThreadqjgddlProcess()
        {
            while (TreadRun)
            {
                InsertData("qjgddl", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("qjgddl_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("qjgddl_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(89000);
            }
        }
        private void ThreadupsProcess()
        {
            while (TreadRun)
            {
                InsertData("ups", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("ups_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("ups_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(93000);
            }
        }

        private void ThreaddypProcess()
        {
            while (TreadRun)
            {
                InsertData("dyp", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("dyp_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("dyp_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(10800);
            }
        }

        private void ThreadbzbProcess()
        {
            while(TreadRun)
            {
                InsertData("bzb", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("bzb_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("bzb_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(7900);
            }
        }

        private void ThreadwdwProcess()
        {
            while (TreadRun)
            {
                InsertData("wdw", InsertRow_Sum, InsertDev_Sum);
                InsertData_15Column("wdw_c", InsertRow_Sum, InsertDev_Sum);
                InsertData_20Column("wdw_c20", InsertRow_Sum, InsertDev_Sum);
                Thread.Sleep(6400);
            }
        }




        protected override void OnClosing(CancelEventArgs e)
        {
            if (c != null) c.StopServices(true);
            TreadRun = false;
            Thread.Sleep(200);  //暂停100ms，等待现场池关闭            
            base.OnClosing(e);
        }
                
        

        void InsertBZB_Time_Tick(object sender, EventArgs e)
        {
            InsertBZB_Time.Stop();
            InsertData("bzb", InsertRow_Sum, InsertDev_Sum);
            InsertBZB_Time.Start();
        }

        void InsertZNGDDL_Time_Tick(object sender, EventArgs e)
        {
            InsertZNGDDL_Time.Stop();
            InsertData("zngddl", InsertRow_Sum, InsertDev_Sum);
            InsertZNGDDL_Time.Start();
        }

        void InsertZHANLIAN_Time_Tick(object sender, EventArgs e)
        {
            InsertZHANLIAN_Time.Stop();
            InsertData("zhanlian", InsertRow_Sum, InsertDev_Sum);
            InsertZHANLIAN_Time.Start();
        }

        void InsertXHJ_Time_Tick(object sender, EventArgs e)
        {
            InsertXHJ_Time.Stop();
            InsertData("xhj", InsertRow_Sum, InsertDev_Sum);
            InsertXHJ_Time.Start();
        }

        void InsertWDW_Time_Tick(object sender, EventArgs e)
        {
            InsertWDW_Time.Stop();
            InsertData("wdw", InsertRow_Sum, InsertDev_Sum);
            InsertWDW_Time.Start();
        }

        void InsertUPS_Time_Tick(object sender, EventArgs e)
        {
            InsertUPS_Time.Stop();
            InsertData("ups", InsertRow_Sum, InsertDev_Sum);
            InsertUPS_Time.Start();
        }

        void InsertQJGDDL_Time_Tick(object sender, EventArgs e)
        {
            InsertQJGDDL_Time.Stop();
            InsertData("qjgddl", InsertRow_Sum, InsertDev_Sum);
            InsertQJGDDL_Time.Start();
        }

        void InsertMCGDDL_Time_Tick(object sender, EventArgs e)
        {
            InsertMCGDDL_Time.Stop();
            InsertData("mcgddl", InsertRow_Sum, InsertDev_Sum);
            InsertMCGDDL_Time.Start();
        }

        void InsertDYP_Time_Tick(object sender, EventArgs e)
        {
            InsertDYP_Time.Stop();
            InsertData("dyp", InsertRow_Sum, InsertDev_Sum);
            InsertDYP_Time.Start();
        }

        void InsertDMH_Time_Tick(object sender, EventArgs e)
        {
            InsertDMH_Time.Stop();
            InsertData("dmh", InsertRow_Sum, InsertDev_Sum);
            InsertDMH_Time.Start();
        }

        void InsertDCBSDY_Time_Tick(object sender, EventArgs e)
        {
            InsertData("dcbsdy", InsertRow_Sum, InsertDev_Sum);
        }

        

        void time_Tick(object sender, EventArgs e)
        {
            if ((c != null) && c.State == PoolState.Run)
            {
                ConnectSum.Text = c.RealFormPool.ToString();
                OnUseSum.Text = c.UseFormPool.ToString();
                NullSum.Text = c.SpareRealFormPool.ToString();
            }
            labelBigCtime.Text = T_labelBigCtime;
            labelBigStime.Text = T_labelBigStime;
            label_bigCount.Text = TableCountSum.ToString();
        }

        
        //void InsertTime_Tick(object sender, EventArgs e)
        //{
        //    if (TABLE_NAME.Text != "")
        //    {
        //        InsertData(TABLE_NAME.Text,1,1500);
        //    }


        public static long DateTimeToTime_t(DateTime dateTime)
        {
            long time_t;
            DateTime dt1 = new DateTime(1970, 1, 1, 0, 0, 0);
            TimeSpan ts = dateTime - dt1;
            time_t = ts.Ticks / 10000000 - 28800;
            return time_t;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (TABLE_NAME.Text == "" || (TABLE_NAME.Text).ToLower() == "analogtable")
            {
                TABLE_NAME.Text = "analogtable";
                DesignColumnNum = 31;
                DesignMaxSize_Column = 500;
                Enable_Button(1);
            }
            else if ((TABLE_NAME.Text).ToLower() == "test_analogtable")
            {
                DesignColumnNum = 200;
                DesignMaxSize_Column = 10;
                Enable_Button(1);
            }
            else if ((TABLE_NAME.Text).ToLower() == "test1000w")
            {
                DesignColumnNum = 60;
                DesignMaxSize_Column = 3;
                Enable_Button(0);
                TableType = 0;
            }
            else if ((TABLE_NAME.Text).ToLower() == "test1000w_copy")
            {
                DesignColumnNum = 30;
                DesignMaxSize_Column = 3;
                Enable_Button(0);
                TableType = 0;
            }
            else
            {
                string TmpName = TABLE_NAME.Text.ToLower();
                if (TmpName == "dyp" || TmpName == "ups" || TmpName == "wdw" || TmpName == "zngddl" || TmpName == "qjgddl" || TmpName == "mcgddl")
                {
                    DesignColumnNum = 1;
                    DesignMaxSize_Column = 4;
                    Enable_Button(0);
                    TableType = 1;
                }
                else if (TmpName == "dcbsdy" || TmpName == "xhj" || TmpName == "dmh" || TmpName == "mcgddl" || TmpName == "zhanlian" || TmpName == "zhanlian")
                {
                    DesignColumnNum = 1;
                    DesignMaxSize_Column = 4;
                    Enable_Button(0);
                    TableType = 1;
                }
                else
                {
                    MessageBox.Show("请输入正确的表名,默认analogtable");
                    TABLE_NAME.Text = "analogtable";
                    DesignColumnNum = 31;
                    DesignMaxSize_Column = 500;
                    Enable_Button(1);
                }
            }
            li.Clear();
            for (int i = 1; i < DesignColumnNum + 1; i++)
            {
                List<byte> c1 = new List<byte>();
                for (int j = 0; j < DesignMaxSize_Column; j++)
                {
                    c1.Add((byte)((j * i) + i));
                }
                li.Add(i.ToString(), c1);
            }

            li_15.Clear();

            int d1 = (int)DateTimeToTime_t(DateTime.Now);
            for (int i = 1; i < 15 + 1; i++)
            {
                List<long> c1 = new List<long>();
                long t_value = (d1 << 16);
                for (int j = 0; j < 15; j++)
                {
                    t_value += (j * i + i);
                    c1.Add(t_value);
                }
                li_15.Add(i.ToString(), c1);
            }

            thread_dyp.Start();
            thread_ups.Start();
            thread_wdw.Start();
            thread_zngddl.Start();
            thread_qjgddl.Start();
            thread_mcgddl.Start();
            thread_dcbsdy.Start();
            thread_xhj.Start();
            thread_dmh.Start();
            thread_zhanlian.Start();
            thread_bzb.Start();
        }

 

        private void InsertData(string TableName,int Row,int Dev_Num)
        {
            Dictionary<string, List<string>>tmpRow = new Dictionary<string,List<string>>();
            for (int i = 1; i < Row+1; i++)
            {
                List<string> tmpS = new List<string>();
                for (int k = 0; k < Dev_Num; k++)
                {
                    string s = string.Format("?p_day{0},?u_time{0},?Dev_no{0},?value{0}",k);
                    tmpS.Add(s);
                }
                tmpRow.Add(i.ToString(),tmpS);
            }

            if (c != null && c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + "time" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + (MySql.key++).ToString();
//                using (con = (MySqlConnection)c.GetConnectionFormPool(key))
                {

                    try
                    {
                        con = (MySqlConnection)c.GetConnectionFormPool(key);
                    }
                    catch (MySqlException ex)
                    {
                        Console.WriteLine(ex);
                        return;
                    }
                    if (con!=null)
                    {
                        c_time = (int)DateTimeToTime_t(DateTime.Now);
                        c_day = DateTime.Now.Day;
                        StringBuilder InsertStatement = new StringBuilder();
                        //Row = 1;
                        //Dev_Num = 1;
                        for (int i = 0; i < Row; i++)
                        {
                            //一次插入多行

                            InsertStatement.Clear();
                            InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,value)values", TableName));
                            for (int k = 0; k < Dev_Num - 1; k++)
                            {
                                InsertStatement.Append(string.Format("({0}),", tmpRow[(i + 1).ToString()][k].ToString()));
                            }
                            InsertStatement.Append(string.Format("({0})", tmpRow[(i + 1).ToString()][Dev_Num - 1].ToString()));

                            using (MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con))
                            {
                                for (int k = 0; k < Dev_Num; k++)
                                {
                                    string tmpSP_day = string.Format("?p_day{0}", k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpSP_day, MySqlDbType.Int32)).Value = c_day;
                                    string tmpU_time = string.Format("?u_time{0}", k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpU_time, MySqlDbType.Int32)).Value = c_time;
                                    string tmpDev_no = string.Format("?Dev_no{0}", k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpDev_no, MySqlDbType.Int32)).Value = k + 1;
                                    string tmpValue = string.Format("?value{0}", k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpValue, MySqlDbType.Binary)).Value = li[1.ToString()].ToArray();
                                }
                                try
                                {
                                    InsertCommand.CommandTimeout = 300;
                                    InsertCommand.ExecuteNonQuery();
                                }
                                catch (MySqlException ex)
                                {
                                    Console.WriteLine("Error:  " + ex);
                                }
                            }
                        }



                        //for (int k = 0; k < Dev_Num; k++)
                        //{
                        //    if (TableType == 0)
                        //    {
                        //        InsertStatement.Clear();
                        //        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,", TableName));
                        //        for (int m = 1; m < DesignColumnNum; m++)
                        //        {
                        //            InsertStatement.Append(string.Format("c{0},", m));
                        //        }
                        //        InsertStatement.Append(string.Format("c{0})values(?p_day,?u_time,?Dev_no,", DesignColumnNum));
                        //        for (int m = 1; m < DesignColumnNum; m++)
                        //        {
                        //            InsertStatement.Append(string.Format("?c{0},", m));
                        //        }
                        //        InsertStatement.Append(string.Format("?c{0})", DesignColumnNum));
                        //        //Console.WriteLine(InsertStatement.ToString());
                        //        try
                        //        {
                        //            MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Int32)).Value = c_day;
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.Int32)).Value = c_time++;
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?Dev_no", MySqlDbType.Int32)).Value = k + 1;

                        //            for (int m = 1; m < DesignColumnNum; m++)
                        //            {
                        //                string c_tmp = string.Format("?c{0}", m);
                        //                InsertCommand.Parameters.Add(new MySqlParameter(c_tmp, MySqlDbType.VarBinary)).Value = li[m.ToString()].ToArray();
                        //            }
                        //            string c_tmpt = string.Format("?c{0}", DesignColumnNum);
                        //            InsertCommand.Parameters.Add(new MySqlParameter(c_tmpt, MySqlDbType.VarBinary)).Value = li[DesignColumnNum.ToString()].ToArray();
                        //            InsertCommand.CommandTimeout = 120;     //设置120秒超时
                        //            InsertCommand.ExecuteNonQuery();
                        //        }
                        //        catch (MySqlException ex)
                        //        {
                        //            Console.WriteLine("Error:  " + ex);
                        //        }
                        //    }
                        //    else
                        //    {
                        //        InsertStatement.Clear();

                        //        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,value)values(?p_day,?u_time,?Dev_no,?value),(?p_day1,?u_time1,?Dev_no1,?value1)", TableName));
                        //        try
                        //        {
                        //            MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Int32)).Value = c_day;
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.Int32)).Value = c_time++;
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?Dev_no", MySqlDbType.Int32)).Value = k + 1;
                        //            InsertCommand.Parameters.Add(new MySqlParameter("?value", MySqlDbType.VarBinary)).Value = li["1"].ToArray(); //只初始化了一列的值
                        //            InsertCommand.CommandTimeout = 120;
                        //            InsertCommand.ExecuteNonQuery();
                        //        }
                        //        catch (MySqlException ex)
                        //        {
                        //            Console.WriteLine("Error:  " + ex);
                        //        }
                        //    }
                        //}
                        c.DisposeConnection(key);
                    }
                }
            }                
        }

        private void InsertData_15Column(string TableName, int Row, int Dev_Num)
        {
            //Row = 1;
            //Dev_Num = 1;
            Dictionary<string, List<string>> tmpRow = new Dictionary<string, List<string>>();
            for (int i = 1; i < Row + 1; i++)
            {
                List<string> tmpS = new List<string>();
                for (int k = 0; k < Dev_Num; k++)
                {
                    string s = string.Format("?p_day{0},?u_time{0},?Dev_no{0},?value1_{0},?value2_{0},?value3_{0},?value4_{0},?value5_{0},?value6_{0},?value7_{0},?value8_{0},?value9_{0},?value10_{0},?value11_{0},?value12_{0},?value13_{0},?value14_{0},?value15_{0}", k);
                    tmpS.Add(s);
                }
                tmpRow.Add(i.ToString(), tmpS);
            }

            if (c != null && c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + "time" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + (MySql.key++).ToString();
                try
                {
                    con = (MySqlConnection)c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex);
                    return;
                }

                if (con != null)
                {
                    c_time = (int)DateTimeToTime_t(DateTime.Now);
                    c_day = DateTime.Now.Day;
                    StringBuilder InsertStatement = new StringBuilder();
                    //Row = 1;
                    //Dev_Num = 1;
                    for (int i = 0; i < Row; i++)
                    {
                        //一次插入多行

                        InsertStatement.Clear();
                        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value14,value15)values", TableName));
                        for (int k = 0; k < Dev_Num - 1; k++)
                        {
                            InsertStatement.Append(string.Format("({0}),", tmpRow[(i + 1).ToString()][k].ToString()));
                        }
                        InsertStatement.Append(string.Format("({0})", tmpRow[(i + 1).ToString()][Dev_Num - 1].ToString()));

                        //Console.WriteLine(InsertStatement.ToString());

                        using( MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con))
                        {
                            long[] TmpValue = new long[15];
                            for (int m = 0; m < 15; m++)
                            {
                                long tm = c_time + m;
                                tm = (tm << 16);
                                tm += m * 100 + m;
                                TmpValue[m] = tm;
                            }

                            for (int k = 0; k < Dev_Num; k++)
                            {
                                string tmpSP_day = string.Format("?p_day{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpSP_day, MySqlDbType.Int32)).Value = c_day;
                                string tmpU_time = string.Format("?u_time{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpU_time, MySqlDbType.Int32)).Value = c_time;
                                string tmpDev_no = string.Format("?Dev_no{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpDev_no, MySqlDbType.Int32)).Value = k + 1;

                                for (int m = 1; m < 16; m++)
                                {
                                    string tmpValue = string.Format("?value{0}_{1}", m, k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpValue, MySqlDbType.Int64)).Value = TmpValue[m - 1];
                                }
                            }    
                            try
                            {
                                InsertCommand.CommandTimeout = 120;
                                InsertCommand.ExecuteNonQuery();
                            }
                            catch (MySqlException ex)
                            {
                                Console.WriteLine("Error:  " + ex);
                            }
                        }                        
                    }
                    c.DisposeConnection(key);
                }
            }
        }


        private void InsertData_20Column(string TableName, int Row, int Dev_Num)
        {
            //Row = 1;
            //Dev_Num = 1;
            Dictionary<string, List<string>> tmpRow = new Dictionary<string, List<string>>();
            for (int i = 1; i < Row + 1; i++)
            {
                List<string> tmpS = new List<string>();
                for (int k = 0; k < Dev_Num; k++)
                {
                    string s = string.Format("?p_day{0},?u_time{0},?Dev_no{0},?value1_{0},?value2_{0},?value3_{0},?value4_{0},?value5_{0},?value6_{0},?value7_{0},?value8_{0},?value9_{0},?value10_{0},?value11_{0},?value12_{0},?value13_{0},?value14_{0},?value15_{0},?value16_{0},?value17_{0},?value18_{0},?value19_{0},?value20_{0}", k);
                    tmpS.Add(s);
                }
                tmpRow.Add(i.ToString(), tmpS);
            }

            if (c != null && c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + "time" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + (MySql.key++).ToString();
                try
                {
                    con = (MySqlConnection)c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex);
                    return;
                }

                if (con != null)
                {
                    c_time = (int)DateTimeToTime_t(DateTime.Now);
                    c_day = DateTime.Now.Day;
                    StringBuilder InsertStatement = new StringBuilder();
                    //Row = 1;
                    //Dev_Num = 1;
                    for (int i = 0; i < Row; i++)
                    {
                        //一次插入多行

                        InsertStatement.Clear();
                        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value14,value15,value16,value17,value18,value19,value20)values", TableName));
                        for (int k = 0; k < Dev_Num - 1; k++)
                        {
                            InsertStatement.Append(string.Format("({0}),", tmpRow[(i + 1).ToString()][k].ToString()));
                        }
                        InsertStatement.Append(string.Format("({0})", tmpRow[(i + 1).ToString()][Dev_Num - 1].ToString()));

                        //Console.WriteLine(InsertStatement.ToString());

                        using (MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con))
                        {
                            int[] TmpValue = new int[20];
                            for (int m = 0; m < 20; m++)
                            {
                                int tm = m;
                                tm = (tm << 16);
                                tm += m * 100 + m;
                                TmpValue[m] = tm;
                            }

                            for (int k = 0; k < Dev_Num; k++)
                            {
                                string tmpSP_day = string.Format("?p_day{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpSP_day, MySqlDbType.Int32)).Value = c_day;
                                string tmpU_time = string.Format("?u_time{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpU_time, MySqlDbType.Int32)).Value = c_time;
                                string tmpDev_no = string.Format("?Dev_no{0}", k);
                                InsertCommand.Parameters.Add(new MySqlParameter(tmpDev_no, MySqlDbType.Int32)).Value = k + 1;

                                for (int m = 1; m < 21; m++)
                                {
                                    string tmpValue = string.Format("?value{0}_{1}", m, k);
                                    InsertCommand.Parameters.Add(new MySqlParameter(tmpValue, MySqlDbType.Int64)).Value = TmpValue[m - 1];
                                }
                            }
                            try
                            {
                                InsertCommand.CommandTimeout = 120;
                                InsertCommand.ExecuteNonQuery();
                            }
                            catch (MySqlException ex)
                            {
                                Console.WriteLine("Error:  " + ex);
                            }
                        }
                    }
                    c.DisposeConnection(key);
                }
            }
        }


        static void MySql_Thread(object o)
        {
            MySQL_Operation obj = new MySQL_Operation();   
            obj = (MySQL_Operation)o;

            if (obj.TableName == "")
            {
                MessageBox.Show("请输入表名称");
                return;
            }
            if (c == null)
            {
                MessageBox.Show("请初始化数据库连接池");
                return;
            }
            

            string key = obj.TableName + obj.OperateType + DateTime.Now.Second.ToString()+DateTime.Now.Millisecond.ToString();
            MySqlConnection conn = new MySqlConnection();

            try
            {                
                conn = (MySqlConnection)c.GetConnectionFormPool(key);
            }
            catch
            {
                MessageBox.Show("数据库连接失败");
            }
            if (conn == null)
            {
                MessageBox.Show("数据库连接池出错,"+key);
            }

            StringBuilder s = new StringBuilder();

            switch (obj.OperateType)
            {
                case Mysql_OperateType.Count:
                    if (obj.p_day == 0)
                    {
                        s.Append(string.Format("select count(*) from {0}", obj.TableName));
                    }
                    else if (obj.p_day <= 31)
                    {
                        s.Append(string.Format("select count(*) from {0} where p_day = {1}", obj.TableName, obj.p_day));
                    }
                    else
                    {
                        MessageBox.Show("无效的天数");
                        break;
                    }
                    try
                    {
                        TableCountSum = 0;
                        DateTime t1 = new DateTime();
                        t1 = DateTime.Now;
                        MySqlCommand comm = new MySqlCommand(s.ToString(), conn);
                        comm.CommandTimeout = 120;   //50s操作超时
                        MySqlDataReader rd = comm.ExecuteReader();
                        rd.Read();
                        TableCountSum = int.Parse(rd.GetValue(0).ToString());
                        rd.Close();
                        T_labelBigCtime = "0";
                        DateTime t2 = new DateTime();
                        t2 = DateTime.Now;
                        double m = t2.Subtract(t1).TotalMilliseconds;
                        T_labelBigCtime = m.ToString();
                        Console.WriteLine(m.ToString());
                    }
                    catch(MySqlException e)
                    {
                        Console.WriteLine("Error:  "+ e.ToString());
                    }
                    break;
                case Mysql_OperateType.Delete:
                    DialogResult dr = MessageBox.Show("数据不可恢复，确认数据?", "删除确认", MessageBoxButtons.OKCancel);
                    if (dr == DialogResult.OK)
                    {
                        if(obj.p_day ==0)
                        {
                            if(obj.SecName == "") s.Append(string.Format("delete * from {0}",obj.TableName));                            
                            else s.Append(string.Format("delete {0} from {1}",obj.SecName,obj.TableName));                            
                        }
                        else if(obj.p_day <=31)
                        {
                            if(obj.SecName == "") s.Append(string.Format("delete * from {0} where p_day = {1} ",obj.TableName,obj.p_day));                            
                            else s.Append(string.Format("delete {0} from {1} where p_day = {2}",obj.SecName,obj.TableName,obj.p_day));
                        }
                        else
                        {
                            MessageBox.Show("无效的天数");
                            break;
                        }
                        try
                        {
                            MySqlCommand delcomm = new MySqlCommand(s.ToString(), conn);
                            delcomm.ExecuteNonQuery();
                        }
                        catch (MySqlException e)
                        {
                            Console.WriteLine("Error:  " + e.ToString());
                        }                        
                    }
                    break;
                case Mysql_OperateType.Insert:
                    if(obj.p_day == 0) obj.p_day = DateTime.Now.Day;
                    break;
                case Mysql_OperateType.Select:
                    if(obj.p_day == 0) obj.p_day = DateTime.Now.Day;
                    if(obj.SecName == "")   //不指定设备，用于回放时取所有模拟量数据，一般需要指定起始时间和开始时间
                    {
                        if(obj.StartUtime == 0 && obj.ColNameSet == "")
                        {//取某天内所有数据
                            s.Append(string.Format("select * from {0} where p_day = {1}",obj.TableName,obj.p_day));
                        }
                        else if(obj.StartUtime !=0 && obj.ColNameSet == "")
                        {//取某天内某一段时间内的所有数据
                            s.Append(string.Format("select * from {0} where p_day = {1} and u_time>={2} and u_time <={3}",obj.TableName,obj.p_day,obj.StartUtime,obj.EndUtime));
                        }
                        else if(obj.StartUtime ==0 && obj.ColNameSet !="")
                        {
                            s.Append(string.Format("select {0} from {1} where p_day = {3}",obj.ColNameSet,obj.TableName,obj.p_day));
                        }
                        else if(obj.StartUtime!=0 && obj.ColNameSet !="")
                        {
                            s.Append(string.Format("select {0} from {1} where p_day = {2} and u_time>={3} and u_time <={4}",obj.ColNameSet,obj.TableName,obj.p_day,obj.StartUtime,obj.EndUtime));
                        }
                    }
                    else
                    {
                        if (obj.StartUtime == 0 && obj.ColNameSet == "")
                        {//取某天内所有数据
                            s.Append(string.Format("select * from {0} where p_day = {1} and dev_no = {2}", obj.TableName, obj.p_day, obj.SecName));
                        }                        
                        else if(obj.StartUtime !=0 && obj.ColNameSet == "")
                        {//取某天内某一段时间内的所有数据
                            s.Append(string.Format("select * from {0} where p_day = {1} and u_time>={2} and u_time <={3} and dev_no = {4}",obj.TableName,obj.p_day,obj.StartUtime,obj.EndUtime,obj.SecName));
                        }
                        else if(obj.StartUtime ==0 && obj.ColNameSet !="")
                        {
                            s.Append(string.Format("select {0} from {1} where p_day = {2} and dev_no = {3}",obj.ColNameSet,obj.TableName,obj.p_day,obj.SecName));
                        }
                        else if(obj.StartUtime!=0 && obj.ColNameSet !="")
                        {
                            s.Append(string.Format("select {0} from {1} where p_day = {2} and u_time>={3} and u_time <={4} and dev_no = {5}",obj.ColNameSet,obj.TableName,obj.p_day,obj.StartUtime,obj.EndUtime,obj.SecName));
                        }
                    }
                    try
                    {
                        Console.WriteLine(s.ToString());
                        T_labelBigStime = "0";
                        DateTime T1 = new DateTime();
                        T1 = DateTime.Now;
                        MySqlCommand selectCommand = new MySqlCommand(s.ToString(), conn);
                        selectCommand.CommandTimeout = 50;   //50s操作超时
                        MySqlDataAdapter da = new MySqlDataAdapter();
                        da.SelectCommand = selectCommand;
                        DataSet ds = new DataSet();
                        da.Fill(ds, obj.TableName);
                        int k = 0;
                        foreach(DataRow row in ds.Tables[obj.TableName].Rows)
                        {
                            k++;
                        }
                        Console.WriteLine(k.ToString());

                        DateTime T2 = new DateTime();
                        T2 = DateTime.Now;
                        T_labelBigStime = T2.Subtract(T1).TotalMilliseconds.ToString();
                        Console.WriteLine(T_labelBigStime.ToString());
                    }
                    catch (MySqlException e)
                    {
                        Console.WriteLine(e);
                    }
                    break;
                default:
                    break;
            }
            try
            {
                c.DisposeConnection(key);
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e);
            }
        }

        private void Enable_Button(int k)
        {
            if (1 == k)
            {
                buttonInsertBig.Enabled = false;
                Button_CountBig.Enabled = false;
                buttonSelectBig.Enabled = false;
                buttondel_big.Enabled = false;
            }
            else
            {
                button_Insert.Enabled = false;
                button_count.Enabled = false;
                button_select.Enabled = false;
                button_del.Enabled = false;
            }           
        }



        private void StartServer_Click(object sender, EventArgs e)
        {
            if (c == null)
            {
                //string ConnectSqlStatement = string.Format("Database=csm2010;Data Source=localhost;Persist Security Info=yes;UserId=root; PWD=;charset= utf8");
                
                //c = new ConnectionPool(ConnectSqlStatement, ConnTypeEnum.MySqlClient);
                //c = new ConnectionPool("csm2010","localhost","yes","root","","utf8");
                if (textDB_NAME.Text == "") textDB_NAME.Text = "csm2010";
                if (TextConnectName.Text == "") TextConnectName.Text = "192.168.10.222";
                //c = new ConnectionPool(textDB_NAME.Text, "localhost");
                c = new ConnectionPool(textDB_NAME.Text, TextConnectName.Text);
                c.MinConnection = int.Parse(Min_Int.Text);
                c.MaxConnection = int.Parse(Max_Int.Text);
                c.MaxRepeatDegree = int.Parse(ReaptNum.Text);
                //c.RunTime = int.Parse(TimeOut.Text);
                c.SeepConnection = int.Parse(CreateNum.Text);
                c.KeepRealConnection = int.Parse(keepNumNum.Text);
                c.StartServices();

                Min_Int.Enabled = false;
                Max_Int.Enabled = false;
                ReaptNum.Enabled = false;
                TimeOut.Enabled = false;
                CreateNum.Enabled = false;
                keepNumNum.Enabled = false;
                StartServer.Enabled = false;                
                Apply_Comm.Enabled = true;
                button_Dispose.Enabled = true;
                stopServers.Enabled = true;
            }
            else 
            {
                MessageBox.Show("服务已经启动");
            }
        }

        private void StartServer_Click()
        {
            if (MySql.c == null)
            {

                MySql.c = new ConnectionPool("csm2014", "192.168.10.222");
                MySql.c.MinConnection = 5;
                MySql.c.MaxConnection = 20;
                MySql.c.MaxRepeatDegree = 5;
                //c.RunTime = int.Parse(TimeOut.Text);
                MySql.c.SeepConnection = 3;
                MySql.c.KeepRealConnection = 3;
                MySql.c.StartServices();
                
            }
        }

        private void button_Dispose_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 50; i++)
            {
                if (conn[i] != null)
                {
                    try
                    {
                        c.DisposeConnection(i);
                        conn[i]= null;
                        break;
                    }
                    catch
                    { }
                }
            }
        }

        private void Apply_Comm_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 50; i++)
            {
                if (conn[i] == null)
                {
                    try
                    {
                        conn[i]  = (MySqlConnection)c.GetConnectionFormPool(i, ConnLevel.None);
                        if (conn[i] == null) MessageBox.Show("未能获取连接，请查看log文件");
                    }
                    catch
                    { }
                    break;
                }
            }
        }

        private void stopServers_Click(object sender, EventArgs e)
        {
            try
            {
                if (c != null)
                {
                    c.StopServices();
                    c = null;
                    Apply_Comm.Enabled = false;
                    button_Dispose.Enabled = false;
                    stopServers.Enabled = false;
                    StartServer.Enabled = true;
                    ConnectSum.Text = "";
                    OnUseSum.Text = "";
                    NullSum.Text = "";
                    Min_Int.Enabled = true;
                    Max_Int.Enabled = true;
                    ReaptNum.Enabled = true;
                    TimeOut.Enabled = true;
                    CreateNum.Enabled = true;
                    keepNumNum.Enabled = true;
                }
                else MessageBox.Show("请先启动服务");
            }
            catch { MessageBox.Show("数据库连接池出错"); }            
        }

        private void Max_Int_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void Min_Int_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void TimeOut_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void ReaptNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void CreateNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void keepNumNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))//判断是否为数字
            {
                MessageBox.Show("请输入数字！", "提示！",//弹出消息对话框
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;//取消在控件中显示该字符
            }
        }

        private void button_Insert_Click(object sender, EventArgs e)
        {

            if (TABLE_NAME.Text == "") TABLE_NAME.Text = "analogtable";

            StringBuilder InsertStatement = new StringBuilder(string.Format("insert into {0}(p_day,u_time,",TABLE_NAME.Text));
            for (int i = 1; i < DesignColumnNum; i++)
            {
                InsertStatement.Append(string.Format("c{0},",i));
            }
            InsertStatement.Append(string.Format("c{0})values(?p_day,?u_time,",DesignColumnNum));
            for (int i = 1; i < DesignColumnNum; i++)
            {
                InsertStatement.Append(string.Format("?c{0},", i));
            }
            InsertStatement.Append(string.Format("?c{0})",DesignColumnNum));

            MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1005);
            
            if (con != null)
            {
                int Row = 1;
                if (text_insetRowNum.Text == "") text_insetRowNum.Text = "1";
                
                Row = int.Parse(text_insetRowNum.Text);

                if (text_day.Text == "") text_day.Text = DateTime.Now.Day.ToString();
                c_day = int.Parse(text_day.Text);
                DateTime t = DateTime.Now;
                for (int k = 0; k < Row; k++)
                {
                    try
                    {
                        MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                        InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Int32)).Value = c_day;
                        InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.Int32)).Value = c_time++;

                        for (int i = 1; i < DesignColumnNum; i++)
                        {
                            string c_tmp = string.Format("?c{0}", i);
                            InsertCommand.Parameters.Add(new MySqlParameter(c_tmp, MySqlDbType.VarBinary)).Value = li[i.ToString()].ToArray();
                        }
                        string c_tmpt = string.Format("?c{0}", DesignColumnNum);
                        InsertCommand.Parameters.Add(new MySqlParameter(c_tmpt, MySqlDbType.VarBinary)).Value = li[DesignColumnNum.ToString()].ToArray();

                        InsertCommand.ExecuteNonQuery();                        
                    }
                    catch (MySqlException ex)
                    {                        
                        Console.WriteLine("Error: " + ex);
                    }
                }
                DateTime t1 = DateTime.Now;
                double m = t1.Subtract(t).TotalMilliseconds;
                label_Inserttime.Text = m.ToString();
            }
            c.DisposeConnection(1005);
        }

        private void button_count_Click(object sender, EventArgs e)
        {
            MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1006);
            
            if (con != null)
            {
                try
                {
                    if (TABLE_NAME.Text == "") TABLE_NAME.Text = "analogtable";
                    if (text_c_day.Text == "") text_c_day.Text = DateTime.Now.Day.ToString();
                    String CountStatement = string.Format("select count(*) from {0} where p_day = {1}", TABLE_NAME.Text, int.Parse(text_c_day.Text));
                    MySqlCommand CountCommand = new MySqlCommand(CountStatement, con);

                    DateTime t = DateTime.Now;
                    MySqlDataReader rd = CountCommand.ExecuteReader();
                    rd.Read();
                    label_allRow.Text = rd.GetValue(0).ToString();
                    rd.Close();
                    DateTime t1 = DateTime.Now;
                    int m = t1.Subtract(t).Milliseconds;
                    label_countTime.Text = m.ToString();
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine("Error: " + ex);
                }
            }
            c.DisposeConnection(1006);
        }

        private void button_select_Click(object sender, EventArgs e)
        {
            MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1007);
            
            if (con != null)
            {
                try
                {
                    if (TABLE_NAME.Text == "") TABLE_NAME.Text = "analogtable";
                    if (text_s_day.Text == "") text_s_day.Text = DateTime.Now.Day.ToString();
                    StringBuilder s = new StringBuilder();
                    if (text_time.Text != "" && text_col.Text != "" && textbyte.Text != "" && textlength.Text != "")
                    {   //指定行指定列的某一些值
                        s.Append(string.Format("select mid({0},{1},{2})from {5} where p_day ={3} and u_time ={4}", text_col.Text, int.Parse(textbyte.Text), int.Parse(textlength.Text), int.Parse(text_s_day.Text), int.Parse(text_time.Text), TABLE_NAME.Text));
                    }
                    else if (text_time.Text != "" && text_col.Text == "")
                    {   //指定行某一列的所有值
                        s.Append(string.Format("select * from {2} where p_day={0} and u_time = {1}", int.Parse(text_s_day.Text), int.Parse(text_time.Text), TABLE_NAME.Text));
                    }
                    else if (text_time.Text != "" && text_col.Text != "")
                    {   //指定行指定列的所有值
                        s.Append(string.Format("select {0} from {3} where p_day={1} and u_time = {2}", text_col.Text, int.Parse(text_s_day.Text), int.Parse(text_time.Text), TABLE_NAME.Text));
                    }
                    else if (text_time.Text == "" && text_col.Text != "")
                    {   //指定列的所有值
                        s.Append(string.Format("select {0} from {2} where p_day = {1} and no>=10000 and no<=40000 limit 10000", text_col.Text, int.Parse(text_s_day.Text), TABLE_NAME.Text));
                    }
                    else s.Append(string.Format("select * from {1} where p_day = {0}", int.Parse(text_s_day.Text), TABLE_NAME.Text));

                    DateTime t = DateTime.Now;

                    for (int i = 0; i < 9; i++)
                    {
                        s.Clear();

                        s.Append(string.Format("select {0} from {1} where p_day = {2} and no>={3}*10000 and no<=({4}+1)*10000", text_col.Text, TABLE_NAME.Text, int.Parse(text_s_day.Text), i, i));
                        Console.WriteLine(s.ToString());
                        MySqlCommand cn = new MySqlCommand(s.ToString(), con);
                        cn.CommandTimeout = 100;
                        MySqlDataReader aread = cn.ExecuteReader();
                        int l = 0;
                        while (aread.Read())
                        {
                            l++;
                            aread.GetString(0);
                        }
                        Console.WriteLine(l.ToString());
                        aread.Close();
                    }

                    //MySqlCommand cn = new MySqlCommand(s.ToString(), con);
                    //cn.CommandTimeout = 100;
                    //MySqlDataReader aread = cn.ExecuteReader();
                    //int l = 0;
                    //while (aread.Read())
                    //{
                    //    l++;
                    //    aread.GetString(0);
                    //}
                    //aread.Close();
                    //Console.WriteLine(l.ToString());
                    
                    DateTime t1 = DateTime.Now;
                    double m = t1.Subtract(t).TotalMilliseconds;
                    labeltime.Text = m.ToString();
                    Console.WriteLine(m.ToString());
                    


                    //cn.CommandTimeout = 50;
                    //MySqlDataAdapter dap = new MySqlDataAdapter();
                    //dap.SelectCommand = cn;
                    //DataSet ds = new DataSet();
                    //DateTime t = DateTime.Now;
                    //dap.Fill(ds, TABLE_NAME.Text);
                    //DateTime t1 = DateTime.Now;
                    //double m = t1.Subtract(t).TotalMilliseconds;
                    //labeltime.Text = m.ToString();

                    //DataTable dt = ds.Tables["analogtable"];
                    //int[] tmpB = new int[1000];
                    //int i = 0;
                    //int t_day = (int)dt.Rows[0][0];
                    //int t_time = (int)dt.Rows[0][1];
                    //if (dt != null)
                    //{
                    //    foreach (DataRow dr in dt.Rows)
                    //    {
                    //       // string Tmp = dr[i][0].ToString();
                    //        //foreach (DataColumn cr in dt.Columns)
                    //        //{
                    //        //    tmpB[i] = ();
                    //        //    i++;
                    //        //}
                    //    }
                    //}
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine("Error：" + ex);
                }

            }
            c.DisposeConnection(1007);
        }

        private void button_del_Click(object sender, EventArgs e)
        {
            MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1008);
            if (con != null)
            {
                if (text_DelTime.Text == "")
                {
                    //MessageBox.Show("请输入时间");
                    DialogResult dr = MessageBox.Show("数据不可恢复，确认删除全部数据?", "删除确认", MessageBoxButtons.OKCancel);
                    if (dr == DialogResult.OK)
                    {
                        try
                        {
                            DateTime t1 = DateTime.Now;
                            if (TABLE_NAME.Text == "") TABLE_NAME.Text = "analogtable";
                            if (text_d_day.Text == "") text_d_day.Text = DateTime.Now.Day.ToString();
                            string DelStatement = string.Format("delete from {0} where p_day = {1}",TABLE_NAME.Text,int.Parse(text_d_day.Text));
                            MySqlCommand delcommand = new MySqlCommand(DelStatement, con);
                            delcommand.ExecuteNonQuery();
                            DateTime t2 = DateTime.Now;
                            int m = t2.Subtract(t1).Milliseconds;
                            label_delTime.Text = m.ToString();
                        }
                        catch (MySqlException ex)
                        {
                            Console.WriteLine("Error:" + ex);
                        }
                    }
                }
                else
                {
                    try
                    {
                        DateTime t1 = DateTime.Now;
                        if (TABLE_NAME.Text == "") TABLE_NAME.Text = "analogtable";
                        if (text_d_day.Text == "") text_d_day.Text = DateTime.Now.Day.ToString();
                        int t = int.Parse(text_DelTime.Text);
                        string DelStatement = string.Format("delete from {0} where p_day ={1} and u_time = {1}",TABLE_NAME.Text, int.Parse(text_d_day.Text), t);
                        MySqlCommand delcommand = new MySqlCommand(DelStatement, con);
                        delcommand.ExecuteNonQuery();
                        DateTime t2 = DateTime.Now;
                        int m = t2.Subtract(t1).Milliseconds;
                        label_delTime.Text = m.ToString();
                    }
                    catch (MySqlException ex)
                    {
                        Console.WriteLine("Error:" + ex);
                    }
                }
            }
            c.DisposeConnection(1008);
        }

        private void buttonInsertBig_Click(object sender, EventArgs e)
        {
            if (TABLE_NAME.Text == "") return;
            if (textBigDay.Text == "") textBigDay.Text = DateTime.Now.Day.ToString();
            if (textSecNum.Text == "") textSecNum.Text = "200";
            if (textBigRowNum.Text == "") textBigRowNum.Text = "1";

            int TmpBigRowNum = int.Parse(textBigRowNum.Text);
            int TmpBigSecNum = int.Parse(textSecNum.Text);

            StringBuilder InsertStatement = new StringBuilder();
            MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1005);

            DateTime t1 = DateTime.Now;
            c_day = int.Parse(textBigDay.Text);
            for (int i = 0; i < TmpBigRowNum; i++)
            {
                for (int k = 0; k < TmpBigSecNum; k++)
                {                    
                    if (TableType == 0)
                    {
                        InsertStatement.Clear();
                        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,", TABLE_NAME.Text));
                        for (int m = 1; m < DesignColumnNum; m++)
                        {
                            InsertStatement.Append(string.Format("c{0},", m));
                        }
                        InsertStatement.Append(string.Format("c{0})values(?p_day,?u_time,?Dev_no,", DesignColumnNum));
                        for (int m = 1; m < DesignColumnNum; m++)
                        {
                            InsertStatement.Append(string.Format("?c{0},", m));
                        }
                        InsertStatement.Append(string.Format("?c{0})", DesignColumnNum));
                        //Console.WriteLine(InsertStatement.ToString());
                        try
                        {
                            MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                            InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Int32)).Value = c_day;
                            InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.Int32)).Value = c_time++;
                            InsertCommand.Parameters.Add(new MySqlParameter("?Dev_no", MySqlDbType.Int32)).Value = k + 1;

                            for (int m = 1; m < DesignColumnNum; m++)
                            {
                                string c_tmp = string.Format("?c{0}", m);
                                InsertCommand.Parameters.Add(new MySqlParameter(c_tmp, MySqlDbType.VarBinary)).Value = li[m.ToString()].ToArray();
                            }
                            string c_tmpt = string.Format("?c{0}", DesignColumnNum);
                            InsertCommand.Parameters.Add(new MySqlParameter(c_tmpt, MySqlDbType.VarBinary)).Value = li[DesignColumnNum.ToString()].ToArray();

                            InsertCommand.ExecuteNonQuery();
                        }
                        catch (MySqlException ex)
                        {
                            Console.WriteLine("Error:  " + ex);
                        }
                    }
                    else
                    {
                        InsertStatement.Clear();
                        InsertStatement.Append(string.Format("insert into {0}(p_day,u_time,Dev_no,value)values(?p_day,?u_time,?Dev_no,?value)", TABLE_NAME.Text));
                        try
                        {
                            MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                            InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Int32)).Value = c_day;
                            InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.Int32)).Value = c_time++;
                            InsertCommand.Parameters.Add(new MySqlParameter("?Dev_no", MySqlDbType.Int32)).Value = k + 1;
                            InsertCommand.Parameters.Add(new MySqlParameter("?value", MySqlDbType.VarBinary)).Value = li["1"].ToArray(); //只初始化了一列的值
                            InsertCommand.ExecuteNonQuery();
                        }
                        catch (MySqlException ex)
                        {
                            Console.WriteLine("Error:  " + ex);
                        }
                    }                    
                }
            }
            DateTime t2 = DateTime.Now;
            double x = t2.Subtract(t1).TotalMilliseconds;
            labelBigTime.Text = x.ToString();
            Console.WriteLine(x.ToString());
            c.DisposeConnection(1005);
        }

        private void Button_CountBig_Click(object sender, EventArgs e)
        {
            
            if (TABLE_NAME.Text == "") return;

            MySQL_Operation obj = new MySQL_Operation();
            if (text_BigDay.Text == "") text_BigDay.Text = DateTime.Now.Day.ToString();
            obj.TableName = TABLE_NAME.Text;
            obj.OperateType = Mysql_OperateType.Count;
            obj.p_day = int.Parse(text_BigDay.Text);
            label_bigCount.Text = "";
            labelBigCtime.Text = "";
            ThreadPool.QueueUserWorkItem(new WaitCallback(MySql_Thread),  obj);


            //MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1006);
            //if (con != null)
            //{
            //    try
            //    {
            //        if (text_BigDay.Text == "") text_BigDay.Text = DateTime.Now.Day.ToString();
            //        String CountStatement = string.Format("select count(*) from {0} where p_day = {1}", TABLE_NAME.Text, int.Parse(text_BigDay.Text));
            //        MySqlCommand CountCommand = new MySqlCommand(CountStatement, con);

            //        DateTime t = DateTime.Now;
            //        MySqlDataReader rd = CountCommand.ExecuteReader();
            //        rd.Read();
            //        label_bigCount.Text = rd.GetValue(0).ToString();
            //        rd.Close();
            //        DateTime t1 = DateTime.Now;
            //        double m = t1.Subtract(t).TotalMilliseconds;
            //        labelBigCtime.Text = m.ToString();
            //    }
            //    catch (MySqlException ex)
            //    {
            //        Console.WriteLine("Error: " + ex);
            //    }
            //}
            //c.DisposeConnection(1006);
        }

        private void buttonSelectBig_Click(object sender, EventArgs e)
        {
            if (TABLE_NAME.Text == "") return;

            MySQL_Operation obj = new MySQL_Operation();
            obj.TableName = TABLE_NAME.Text;
            obj.OperateType = Mysql_OperateType.Select;
            if (textBigS_Day.Text == "") textBigS_Day.Text = DateTime.Now.Day.ToString();

            obj.p_day = int.Parse(textBigS_Day.Text);
            if (textBigSec.Text != "") obj.SecName = textBigSec.Text;
            else obj.SecName = "";
            if (textBigCol.Text != "") obj.ColNameSet = textBigCol.Text;
            else obj.ColNameSet = "";
            labelBigStime.Text = "";
            ThreadPool.QueueUserWorkItem(new WaitCallback(MySql_Thread), obj);

            //MySqlConnection con = (MySqlConnection)c.GetConnectionFormPool(1007);
            //if (con != null)
            //{
            //    try
            //    {
            //        if (textBigS_Day.Text == "") textBigS_Day.Text = DateTime.Now.Day.ToString();
            //        StringBuilder s = new StringBuilder();
                    
            //        if (textBigSec.Text != "" && textBigCol.Text == "")
            //        {   //指定某个设备的所有值
            //            s.Append(string.Format("select u_time value from {0} where p_day={1} and Dev_no = {2}",TABLE_NAME.Text, int.Parse(textBigS_Day.Text), int.Parse(textBigSec.Text) ));
            //        }
            //        else if (textBigSec.Text != "" && textBigCol.Text != "")
            //        {   //指定某个设备的某个属性值
            //            s.Append(string.Format("select {0} from {1} where p_day={2} and Dev_no = {3}", textBigCol.Text, TABLE_NAME.Text, int.Parse(textBigS_Day.Text), int.Parse(textBigSec.Text)));
            //        }
            //        else s.Append(string.Format("select * from {1} where p_day = {0}", int.Parse(textBigS_Day.Text), TABLE_NAME.Text));

            //        DateTime t = DateTime.Now;

            //        MySqlCommand cn = new MySqlCommand(s.ToString(), con);
            //        cn.CommandTimeout = 200;
            //        MySqlDataReader aread = cn.ExecuteReader();
            //        int l = 0;
            //        while (aread.Read())
            //        {
            //            aread.GetString(0);
            //            //aread.GetInt32(0);
            //            l++;
            //        }
            //        aread.Close();
            //        Console.WriteLine(l.ToString());
            //        DateTime t1 = DateTime.Now;
            //        double m = t1.Subtract(t).TotalMilliseconds;
            //        labelBigStime.Text = m.ToString();
            //        Console.WriteLine(m.ToString());
            //    }
            //    catch (MySqlException ex)
            //    {
            //        Console.WriteLine("Error：" + ex);
            //    }

            //}
            //c.DisposeConnection(1007);
        }
    }
}
